<?php 
namespace Emos\Field;

use Emos\Common;

class Float extends Integer {
    protected $min = null;
    protected $max = null;
    protected $outOfRangeMessage = null;
    protected $regexp = '/^ -? \d+ (\. \d+)? $/x';
    protected $regexpMessage = 'not a float';    
    
    protected function getPost() {
        return str_replace(',','.', parent::getPost());
    }    
    
    public function setRange($min=0, $max=1000000000, $outOfRangeMessage = null) {
        $this->min = $min;
        $this->max = $max;       
        
        if($outOfRangeMessage === null) {
           $outOfRangeMessage = Common::t("incorrect value"); 
        }        
        
        return $this;
    }
    
    public function getDdlFields() {
        return array(
            $this->dbName => "DOUBLE"
        );
    }    
    
    public function getFake() {
        return array(
            $this->dbName => rand(0, 1000 *100) /100 
        );
    }       
}